home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / diskquot < prev    next >
Text File  |  1993-08-11  |  2KB  |  79 lines

  1. #if defined(USE_QUOTAS)
  2.  
  3. #include <sys/param.h>
  4. #include <sys/quota.h>
  5.  
  6. /*----------------------------------------------------------------------
  7.    Return space left in disk quota on file system which given path is in.
  8.  
  9.     Args: path - Path name of file or directory on file system of concern
  10.           over - pointer to flag that is set if the user is over quota
  11.  
  12.  Returns: If *over = 0, the number of bytes free in disk quota as per
  13.           the soft limit.
  14.       If *over = 1, the number of bytes *over* quota.
  15.           -1 is returned on an error looking up quota
  16.            0 is returned if there is no quota
  17.  
  18. BUG:  If there's more than 2.1Gb free this function will break
  19.   ----*/
  20. long
  21. disk_quota(path, over)
  22.     char *path;
  23.     int  *over;
  24. {
  25.     static int   no_quota = 0;
  26.     struct stat  statx;
  27.     struct dqblk quotax;
  28.     long         q;
  29.  
  30.     if(no_quota)
  31.       return(0L); /* If no quota the first time, then none the second,
  32.                     Also Ultrix seems to give the wrong answer the second
  33.                     time */
  34.  
  35.     dprint(5, (debugfile, "quota_check path: %s\n", path));
  36.     if(stat(path, &statx) < 0) {
  37.         return(-1L);
  38.     }
  39.  
  40.     *over = 0;
  41.     errno = 0;
  42.  
  43.     dprint(7, (debugfile, "Quota check: UID:%d  stat: %d %x\n", 
  44.            getuid(), statx.st_dev, statx.st_dev));
  45.     memset((void *)"ax, 0, sizeof(struct dqblk));
  46.     if(quota(Q_GETDLIM, getuid(), statx.st_dev, "ax) < 0) {
  47.         dprint(5, (debugfile, "Quota failed : %s\n",
  48.                    error_description(errno)));
  49.         if(errno == ESRCH){
  50.             no_quota = 1;
  51.             return(0L); /* No limit */
  52.         } else {
  53.             return(-1L); /* Some thing went wrong */
  54.         }
  55.     }
  56.  
  57.     dprint(5,(debugfile,"Quota: bsoftlimit:%d  bhardlimit:%d  curblock:%d\n",
  58.           quotax.dqb_bsoftlimit, quotax.dqb_bhardlimit, quotax.dqb_curblocks));
  59.  
  60.     /* Some confusion on the type of bsoftlimit. The include file says
  61.        unsigned, but -1 seems to indicate no quota */
  62.     if(quotax.dqb_bsoftlimit == 0 || (long)quotax.dqb_bsoftlimit == -1) {
  63.         no_quota = 1;
  64.         return(0L);
  65.     }
  66.  
  67.     q = (quotax.dqb_bsoftlimit - quotax.dqb_curblocks) * 1024;
  68.  
  69.     if(q < 0) {
  70.         q = -q;
  71.         *over = 1;
  72.     }
  73.     dprint(5, (debugfile, "disk_quota returning :%d,  over:%d\n", q, *over));
  74.     return(q);
  75. }
  76. #endif /* USE_QUOTAS */
  77.  
  78.  
  79.